<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../static/moment/moment.js"></script>
<script src="../static/moment/locale/zh-cn.js"></script>
<title>预算审核</title>
</head>

<body
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">预算审核管理</div>
		</div>
	</div>
	<div class="new-form">
		<div>
			<form id="ff" method="post">
				<table cellpadding="5" style="margin: auto;">
					<tr>
						<td style="width: 100px;">项目：</td>
						<td>
							<input class="easyui-textbox" data-options="readonly:true" id="projectitem" name="projectitem"
								style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">预算类别：</td>
						<td>
							<input class="easyui-textbox" data-options="readonly:true" id="itemcontent" name="itemcontent"
								style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">内容：</td>
						<td colspan="3">
							<input class="easyui-textbox" data-options="readonly:true,multiline:true" id="content" name="content"
								style="width: 100%; height: 100px;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">金额：</td>
						<td colspan="3">
							<input class="easyui-textbox" data-options="readonly:true" id="money" name="money"
								style="width: 100%;" />
						</td>
					</tr>
					<tr>
						<td style="width: 100px;">拒绝理由：</td>
						<td>
							<input class="easyui-textbox" id="reason" name="reason" style="width: 100%; height: 80px;"
								data-options="multiline:true" />
						</td>
					</tr>
				</table>
			</form>
			<div style="text-align: center;" class="search-input">
				<a href="#" class="d-btn btn-blue" onclick="savePro()">同意</a>
				<a href="#" class="d-btn btn-red" onclick="disablecommit()">拒绝</a>
			</div>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro = [[${budgetSubItem}]];
	$(document).ready(function() {
		$("#projectitem").textbox("setValue",currentPro.main.item.name);
		$("#itemcontent").textbox("setValue",currentPro.item.content);
		$("#content").textbox("setValue",currentPro.content);
		$("#money").textbox("setValue",currentPro.money);
	});
	
	function savePro(index) {
		endEditing();
		currentPro = $("#unreviewed_table").datagrid('getRows')[index];
		$.ajax({
			type : 'POST',
			url : "../reviewbudgetmain.do?flg=true&id="+currentPro.id+"&money="+currentPro.money,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.alert('审核预算', '审核预算成功', 'success');
				} else {
					$.messager.alert('审核预算', '审核预算失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}
	
	function disablecommit() {
		var reason = $("#reason").textbox("getValue");
		$.ajax({
			type : 'POST',
			url : "../reviewbudgetmain.do?flg=false&id="+currentPro.id+"&reason="+reason,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.alert('拒绝预算', '拒绝预算成功', 'success');
				} else {
					$.messager.alert('拒绝预算', '拒绝预算失败', 'error');
				}
				window.setInterval("window.location.href=document.referrer", 2000);
			},
			dataType : "json"
		});
	}
	
	$.extend($.fn.textbox.defaults.rules, {
	     number: {//value值为文本框中的值
	           validator: function (value) {
	          var reg = /^\d+(\.\d+)?$/;
	           return reg.test(value);
	       },
     message : "请输入数字"
 		}
 	});
	
	$.extend($.fn.datagrid.methods, {
		editCell: function(jq,param){
			return jq.each(function(){
				var opts = $(this).datagrid('options');
				var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor1 = col.editor;
					if (fields[i] != param.field){
						col.editor = null;
					}
				}
				$(this).datagrid('beginEdit', param.index);
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor = col.editor1;
				}
			});
		}
	});
	
	var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#unreviewed_table').datagrid('validateRow', editIndex)){
			$('#unreviewed_table').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickCell(index, field){
		if (endEditing()){
			$('#unreviewed_table').datagrid('selectRow', index)
					.datagrid('editCell', {index:index,field:field});
			editIndex = index;
		}
	}
	function summoney(){
		$.ajax({
			type : 'GET',
			url : "../reviewed/budgetsubitem.do",
			data:{projectitemid:projectitemid},
			contentType : "application/json",
			success : function(data) {
				var sum = 0;
				$.each(data.rows, function(i,row){      
					sum+= parseFloat(row.money);
				 }); 
				$("#summoney").text(sum.toFixed(2));
			},
			dataType : "json"
		});
	}
</script>
</html>